package com.hh.ssm.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hh.ssm.bean.Employee;
import com.hh.ssm.service.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@Controller
public class EmployeeController {
    @Autowired
    EmployeeService employeeService;

    @RequestMapping("/employees")
    public String getAllEmployees(@RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum, Model model){
        int pageSize = 3;
        PageHelper.startPage(pageNum,pageSize);
        List<Employee> employees = employeeService.getAll();
        int navigatePages = 5;
        PageInfo pageInfo = new PageInfo(employees,navigatePages);
        model.addAttribute("pageInfo",pageInfo);
        return "employees";
    }
}
